<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->

<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_Template.asp
'= 摘    要：后台-模版管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2006-02-14
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"44") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "edit"
	Call Edit
Case "save"
	Call Save
Case "del"
	Call DelTemplate
Case "default"
	Call SaveDefaultTemplate
Case "clone"
	Call CloneTemplate
Case Else
	Call Main
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Main
	Dim TempArray,Temp,i,ListBlock

	PageContent=Template.LoadTemplate("admin_template_list.htm")


	Template.SetVariable "Language_Template_Info",str_Template_Info,PageContent
	Template.SetVariable "Language_Template_TempName",str_Template_TempName,PageContent
	Template.SetVariable "Language_Template_Default",str_Template_Default,PageContent
	Template.SetVariable "Language_Template_CopyTemp",str_Template_CopyTemp,PageContent
	Template.SetVariable "Language_Template_List",str_Template_List,PageContent
	Template.SetVariable "Language_Template_Add",str_Template_Add,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent

	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Submit_Button",str_Comm_Submit_Button,PageContent

	
	TempArray=EA_M_DBO.Get_Template_List()

	ListBlock=Template.GetBlock("list",PageContent)

	If IsArray(TempArray) Then
		For i=0 To UBound(TempArray,2)
			Temp=ListBlock

			Template.SetVariable "TemplateID",TempArray(0,i),Temp
			Template.SetVariable "TemplateName",TempArray(1,i),Temp
			If TempArray(2,i)=1 Then Template.SetVariable "IsDefault"," checked",Temp

			Template.SetBlock "list",Temp,PageContent
		Next
	End If
	Template.CloseBlock "list",PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Edit
	Dim TemplateName,TempStr,StyleId
	Dim Temp
	
	StyleId=EA_Pub.SafeRequest(3,"StyleID",0,0,0)
	
	TempStr=EA_M_DBO.Get_Template_Info(StyleId)
	If IsArray(TempStr) Then TemplateName=TempStr(1,0)

	If Not IsArray(TempStr) Then ReDim TempStr(12,1)

	PageContent=Template.LoadTemplate("admin_template_option.htm")

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent

	Template.SetVariable "Language_Comm_Zoom_Input",str_Comm_Zoom_Input,PageContent
	Template.SetVariable "Language_Comm_Reduce_Input",str_Comm_Reduce_Input,PageContent
	Template.SetVariable "Language_Comm_Save_Button",str_Comm_Save_Button,PageContent
	Template.SetVariable "Language_Comm_Reset_Button",str_Comm_Reset_Button,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent

	Template.SetVariable "Language_Template_Info",str_Template_Info,PageContent
	Template.SetVariable "Language_Template_Manager",str_Template_Manager,PageContent
	Template.SetVariable "Language_Template_TempName",str_Template_TempName,PageContent
	Template.SetVariable "Language_Template_List",str_Template_List,PageContent
	Template.SetVariable "Language_Template_Add",str_Template_Add,PageContent

	Template.SetVariable "Language_Template_Css_Info",str_Template_Css_Info,PageContent
	Template.SetVariable "Language_Template_Head_Info",str_Template_Head_Info,PageContent
	Template.SetVariable "Language_Template_Foot_Info",str_Template_Foot_Info,PageContent
	Template.SetVariable "Language_Template_Index_Info",str_Template_Index_Info,PageContent
	Template.SetVariable "Language_Template_List_Info",str_Template_List_Info,PageContent
	Template.SetVariable "Language_Template_View_Info",str_Template_View_Info,PageContent
	Template.SetVariable "Language_Template_Search_Info",str_Template_Search_Info,PageContent
	Template.SetVariable "Language_Template_ImgList_Info",str_Template_ImgList_Info,PageContent
	Template.SetVariable "Language_Template_MemberList_Info",str_Template_MemberList_Info,PageContent
	Template.SetVariable "Language_Template_Error_Info",str_Template_Error_Info,PageContent
	Template.SetVariable "Language_Template_Success_Info",str_Template_Success_Info,PageContent

	Template.SetVariable "Language_Template_CheckForm",str_Template_CheckForm,PageContent
	Template.SetVariable "Language_Template_CurrentEdit",str_Template_CurrentEdit,PageContent

	Temp=Template.LoadTemplate("head.htm")
	Template.SetVariable "_TOP",Temp,PageContent

	Template.SetVariable "TemplateID",StyleId,PageContent
	Template.SetVariable "TemplateName",TemplateName,PageContent
	
	If TemplateName<>"" then
		dim tempPath,tempContent
		tempPath = TempStr(1,0)&"/"
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Main.CSS") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Main.css")
			Template.SetVariable "CSS",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_Head.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_Head.html")
			Template.SetVariable "Head",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_Foot.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_Foot.html")
			Template.SetVariable "Foot",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_Index.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_Index.html")
			Template.SetVariable "Index",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_List.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_List.html")
			Template.SetVariable "List",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_View.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_View.html")
			Template.SetVariable "View",tempContent,PageContent
		end if
		
		if SiteTemplate.Chk_IsExistsTemplateFile(tempPath&"Page_Search.html") then 
			tempContent=SiteTemplate.LoadTemplate(tempPath&"Page_Search.html")
			Template.SetVariable "Search",tempContent,PageContent
		end if
	else
	
	end if
	'Template.SetVariable "CSS",TempStr(2,0),PageContent
	'Template.SetVariable "Head",TempStr(3,0),PageContent
	'Template.SetVariable "Foot",TempStr(4,0),PageContent
	'Template.SetVariable "Index",TempStr(5,0),PageContent
	'Template.SetVariable "List",TempStr(6,0),PageContent
	'Template.SetVariable "View",TempStr(7,0),PageContent
	'Template.SetVariable "Search",TempStr(8,0),PageContent
'	Template.SetVariable "Member_List",TempStr(9,0),PageContent
'	Template.SetVariable "Img_List",TempStr(10,0),PageContent
'	Template.SetVariable "Error",TempStr(11,0),PageContent
'	Template.SetVariable "Success",TempStr(12,0),PageContent

	Template.OutStr PageContent
End Sub

Sub CloneTemplate
	Call EA_Pub.Chk_Post
	
	Dim TempId
	TempId=EA_Pub.SafeRequest(3,"tempid",0,0,0)
	
	EA_M_DBO.Set_Template_Clone TempId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub SaveDefaultTemplate
	Call EA_Pub.Chk_Post
	
	Dim DefId
	DefId=EA_Pub.SafeRequest(2,"isActive",0,0,0)
	
	If DefId>0 Then EA_M_DBO.Set_DefaultTemplate DefId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub Save
	Call EA_Pub.Chk_Post
	If rs.state=1 Then rs.close

	Dim TemplateContent,TemplateTag
	Dim StyleID
	
	StyleID=EA_Pub.SafeRequest(3,"styleid",0,0,0)
	TemplateContent=EA_Pub.SafeRequest(2,"TemplateContent",1,"",-1)
	TemplateTag=EA_Pub.SafeRequest(2,"TemplateTag",1,"",-1)
	
	If StyleID<>0 Then
		rs.open "select * from NB_Template where id="&StyleID,conn,2,3
	Else
		rs.open "select * from NB_Template",conn,2,3
		rs.addnew
	End If
	dim Folder,sHTMLFilePath
	If TemplateTag = "Name" Then
		rs("Temp_" & TemplateTag)=TemplateContent
		'创建模板文件夹
		Folder="../TemplateFile/"&TemplateContent&"/"
		If Not(EA_Pub.CheckDir(Folder)) Then EA_Pub.MakeNewsDir Folder
	Else
		rs("Page_" & TemplateTag)=TemplateContent
		'创建模板文件
		
				
		If LCase(TemplateTag) = "css" Then
			Dim re
			Set re=new RegExp
			re.IgnoreCase =true
			re.Global=True

			re.Pattern="<style([^>]*)>"
			TemplateContent=re.Replace(TemplateContent,"")

			TemplateContent=Replace(TemplateContent,"</style>","")

			TemplateContent=Replace(TemplateContent,"{$SystemPath$}",SystemFolder)

			sHTMLFilePath = "../TemplateFile/"&rs("Temp_Name")&"/"&"Main"&".css"
			
			Call EA_Pub.Save_HtmlFile(sHTMLFilePath,TemplateContent)
		else
			sHTMLFilePath = "../TemplateFile/"&rs("Temp_Name")&"/"&"Page_" & TemplateTag&".html"
			Call EA_Pub.Save_HtmlFile(sHTMLFilePath,TemplateContent)
		End If
	End If
		rs.update
		
	Rs.Close:Set Rs=Nothing
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub DelTemplate
	Call EA_Pub.Chk_Post
	
	Dim StyleID
	Dim TempStr
	StyleID=EA_Pub.SafeRequest(3,"styleid",0,0,0)
	
	If StyleID>0 Then
		Dim IsDel
		IsDel=False
		
		TempStr=EA_M_DBO.Get_Template_Info(StyleID)
		If IsArray(TempStr) Then 
			'是否是默认模板
			If TempStr(13,0)=0 Then 
				IsDel=True
			Else
				IsDel=False
			End If
		End If
		If IsDel Then 
			EA_M_DBO.Set_Template_Delete StyleID
			'删除模板文件夹
			EA_Pub.DeleteDir "../TemplateFile/"&TempStr(1,0)
		Else
			ErrMsg=str_PassDataError
			Call EA_Manager.Error(1)
		End If
	End If

	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub 
%>